import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import vueJsx from "@vitejs/plugin-vue-jsx";
import AutoImport from "unplugin-auto-import/vite";
import VueDevTools from "vite-plugin-vue-devtools";
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  // 手动加载 `.env` 文件
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue({
        script: {
          propsDestructure: true,
        },
      }),
      vueJsx(),
      AutoImport({
        imports: ["vue", "vue-router", "@vueuse/core"],
        dts: "auto-imports.d.ts",
        dirs: ["src/utils/global"],
        resolvers: [],
      }),
      VueDevTools(),
    ],
    server: {
      port: 80,
      host: true,
      open: false,
      proxy: {
        "/madoka-api": {
          target: env.VITE_PROXY_API,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/madoka-api/, ""),
        },
        "/proxy_yuzhoutianshi": {
          target: env.VITE_YUZHOUTIANSHI_PROXY_API,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/proxy_yuzhoutianshi/, ""),
        },
        "/300_hero_api": {
          target: env.HERO_PROXY_API,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/300_hero_api/, ""),
        }
      },
    },
    base: "",
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
  };
});
